package bTree.LeetCode;

import java.util.Stack;

public class 最小栈 {
    Stack<Integer> stack;
    Stack<Integer> minStatic;

    public 最小栈() {
        stack = new Stack<>();
        minStatic = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if (minStatic.isEmpty()) {
            minStatic.push(val);
        } else {
            minStatic.push(Math.min(val, minStatic.peek()));
        }

    }

    public void pop() {
        stack.pop();
        minStatic.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStatic.peek();
    }
}